# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:chrome_test.py
@Time:2024/10/11 15:50

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep

def convert_to_seconds(time_str):
    # 分割字符串获取分钟和秒
    parts = time_str.split('分')
    minutes = int(parts[0])  # 将分钟转换为整数
    seconds = int(parts[1].replace('秒', ''))  # 移除"秒"并转换为整数

    # 将分钟转换为秒，并加上秒
    total_seconds = minutes * 60 + seconds
    return total_seconds


# 指定 ChromeDriver 的路径
driver_path = 'd:/code_zgq/ganbu/chromedriver.exe'
service = Service(executable_path=driver_path)

# 创建 WebDriver 实例
driver = webdriver.Chrome(service=service)
# driver = webdriver.Chrome()



driver.implicitly_wait(3)
driver.maximize_window()

# 打开网页
driver.get('https://www.sxgbxx.gov.cn/login')

# 等待页面加载完成
wait = WebDriverWait(driver, 10)

# 找到用户名输入框并输入用户名
username_input = wait.until(EC.presence_of_element_located((By.ID, 'userEmail')))
username_input.send_keys('u0122092')

# 找到密码输入框并输入密码
password_input = wait.until(EC.presence_of_element_located((By.ID, 'userPassword')))
password_input.send_keys('071726zgq001!')

# 提示用户输入验证码
# print("按回车继续...")
input("按回车继续...")

driver.get("https://www.sxgbxx.gov.cn/uc/plan/info?id=7baa61f923a0e652")
kecheng_ul = driver.find_element(By.CSS_SELECTOR, 'div.p-cou-wrap.p-l-module > ul')

print(kecheng_ul.get_attribute("outerHTML"))
kecheng = kecheng_ul.find_elements(By.CSS_SELECTOR,'a')

urls = []
for item in kecheng:
    if item.get_attribute('href'):
        new_url= item.get_attribute('href').replace('couinfo','playkpoint')
        # new_url = item.get_attribute('href')
        print(new_url)
        urls.append(new_url)

for url in urls:
    # 登录后可直达网址
    driver.get(url)
    # 得到文件列表,a.play-icon-box 12个图文+视频，a.play-icon-box.image-icon-box，9个，图文
    # articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div a.play-icon-box.image-icon-box")
    articles = driver.find_elements(By.CSS_SELECTOR, "div.n-ct-of > div a.play-icon-box")
    print(articles)
    # 点击后，再判断，如果是图文，sleep(10)，如果是视频，再点播放
    for article in articles:
        item = article.find_element(By.CSS_SELECTOR,"a").click()

        #  如是图文播放
        if item.get_attribute("title") == "图文播放":
            # pass
            # item.find_element(By.CSS_SELECTOR,"a.play-icon-box.image-icon-box").click()
            sleep(10)
            print("图文**************************")
        #  如是视频播放
        if item.get_attribute("title") == "视频播放":
            sleep(20)
            print("视频&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")






